#coding=utf-8

require "aio/core"

class Aio::Module::Cmd::H3C::DisplayVersion < Aio::Module::Cmd::H3C
  include Aio::Module

  def initialize
    super({
      :cmd_full 	=> "display version",
      :cmd_short	=> "dis ver",
      :author			=> "Elin",
      :description => "This is H3C Command# display version",
      :ranking		=> Ranking_1,
      :key_stand	=> true,
      :platform		=> "route",
      :benchmark	=> {
      }
    })
  end

  def parse
    cont = self.context.dup
    soft_info = {}
    useful[:software] = soft_info
    cont.readline_match_block(/(?<device_type>H3C) Comware Platform Software/) do |block|
      key_stand_h3c
    end
    cont.readline_match_block(/Comware Software, Version (?<version>.*)/) do |block|
      block.update(soft_info, :version)
      key_stand_version(block[:version])

      # 按版本来确定
      case block[:version]
      when /^7\./  # 当是7.x 版本的时候，show memory 会不一样
        key_stand_template Template_3
      else
        key_stand_template Template_1
      end

    end
    cont.readline_match_block(/.*/)
    cont.readline_match_block(/H3C (?<device_model>.*) uptime is (?<uptime>.*)/) do |block|
      key_stand_h3c
      block.update(soft_info, :device_model)
      block.update(soft_info, :uptime)
      key_stand_model(block[:device_model])

      # 按设备类型来确定
      case block[:device_model]
      when /3600|8800/ # 当是S3600,S5500,S8800 的时候
        key_stand_template Template_2
      end
    end

    cont.readline_match_block_loop(/\[SubSlot (?<slot_id>\d)\](?<slot>.*)/, reg_blank) do |block|
      next if block[:slot] =~ /No/
      slot_id = block[:slot_id].to_i
      block.update_hash(soft_info, :slot, "slot_#{slot_id}", block[:slot])
    end

  end

end
